package cn.fu.excle;

import java.io.File;
import java.util.List;
/**
 * ���ڲ������ܽ����ļ�
 * @author Foldcc
 *
 */
public class EJtool {
	private ExcelUtils excelUtils = new ExcelUtils();
	private JsonTool jsonTool = new JsonTool();
	private FileUtils fileTool = new FileUtils();
	private EncodeAndDecode encodeTool = new EncodeAndDecode();
	/**
	 * ��ָ��·���µ�excel�ļ�תΪָ��·���ļ�(·��+�ļ�ȫ��) ��ת���ɹ�����true
	 * @param excelFilePath
	 * @param jsonFilePath
	 * @return
	 */
	public boolean ExcelToJson(String excelFilePath , String jsonFilePath){
		boolean isT = false;
		List<String[]> msg = excelUtils.readExcel(new File(excelFilePath));
		if(msg != null){
			String jsonStr = jsonTool.getJsonWithList(msg);
			if(jsonStr != null && fileTool.createFile(jsonFilePath)){
				fileTool.WriteBase(jsonStr, jsonFilePath);
				isT = true;
			}
		}
		return isT;
	}
	
	/**
	 * ��ָ��json��ʽ�ļ�ת��Ϊָ��·��excel�ļ�(·��+�ļ�ȫ��),ת���ɹ�����true
	 * @param jsonFilePath
	 * @param excelFilePath
	 * @return
	 */
	public boolean JsonToExcel(String jsonFilePath , String excelFilePath){
		boolean isT = false;
		String jsonStr = fileTool.ReadBase(jsonFilePath);
		if(jsonStr != null){
			List<String[]> msg = jsonTool.getList(jsonStr);
			if(msg!=null && excelUtils.toExcel(msg, excelFilePath)){
				isT = true;
			}
		}
		return isT;
	}
	
	/**
	 * ��ָ�����ܸ�ʽ��Json�ļ�ת��ΪExcel�ļ�
	 * @param jsonFilePath
	 * @param excelFilePath
	 * @return
	 */
	public boolean JsonToExcelEncode(String jsonFilePath , String excelFilePath){
		boolean isT = false;
		String jsonStr = fileTool.ReadBase(jsonFilePath);
		jsonStr = encodeTool.decode(jsonStr);
		if(jsonStr != null){
			List<String[]> msg = jsonTool.getList(jsonStr);
			if(msg!=null && excelUtils.toExcel(msg, excelFilePath)){
				isT = true;
			}
		}
		return isT;
	}
	
	/**
	 * ��ָ��Excle�ļ�ת��Ϊ���ܸ�ʽ��json�ļ�
	 * @param excelFilePath
	 * @param jsonFilePath
	 * @return
	 */
	public boolean ExcelToJsonEncode(String excelFilePath , String jsonFilePath){
		boolean isT = false;
		List<String[]> msg = excelUtils.readExcel(new File(excelFilePath));
		if(msg != null){
			String jsonStr = jsonTool.getJsonWithList(msg);
			jsonStr = encodeTool.encode(jsonStr);
			if(jsonStr != null && fileTool.createFile(jsonFilePath)){
				fileTool.WriteBase(jsonStr, jsonFilePath);
				isT = true;
			}
		}
		return isT;
	}
}
